home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / atnet.zip / ATNET.C < prev    next >
C/C++ Source or Header  |  1991-08-16  |  5KB  |  214 lines

  1. /*
  2.  * @NET.C
  3.  *
  4.  * Program to provide the same functionallity as the LANtastic NET program
  5.  * with the added ability to process indirect files (i.e. @NET @PARAMS.FIL)
  6. */
  7.  
  8. #include <string.h>
  9. #include <conio.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "lantasti.h"
  13.  
  14. #define   MAX_CMDS       6
  15. #define   MAX_CMD_SIZE   7
  16. #define   MAX_ARGS       10
  17. #define   MAX_ARG_SIZE   40
  18.  
  19. typedef struct
  20.     {
  21.     char            Command [MAX_CMD_SIZE];
  22.     (*Function)    (void);
  23.     } VC;
  24.  
  25. int unuse   (void);
  26. int help    (void);
  27. int login   (void);
  28. int logout  (void);
  29. int lpt     (void);
  30. int unuse   (void);
  31. int use     (void);
  32. int parse   (void);
  33. void ProcessArgs (void);
  34.  
  35. int         indx;
  36. char        **Arguments;
  37. char        **FileArgs;
  38.  
  39. char        Server      [17];
  40. union {
  41.       char        UserID      [17];
  42.       char        Resource    [17];
  43.       } Net;
  44. char        Password    [17];
  45. char        Device      [5];
  46. int         Timeout;
  47.  
  48. VC ValidCommands [MAX_CMDS] =
  49.     {
  50.     "HELP",    help,
  51.     "LOGIN",   login,
  52.     "LOGOUT",  logout,
  53.     "LPT",     lpt,
  54.     "UNUSE",   unuse,
  55.     "USE",     use
  56.     };
  57.  
  58. FILE *CmdStream;
  59. FILE *AltCmdStream;
  60.  
  61. char Buffer [81];
  62.  
  63. int parse (void)
  64. {
  65.     char *src, *dest;
  66.  
  67.     if (strncmp ("\\\\", Arguments [indx], 2) != 0) {
  68.        strcpy (Device, Arguments [indx]);
  69.        indx++;
  70.     } else {
  71.        *Device = '\0';
  72.     }
  73.  
  74.     if (strncmp ("\\\\", Arguments [indx], 2) == 0) {
  75.        src = Arguments [indx] + 2;
  76.        dest = Server;
  77.        while (*src != '\\') {
  78.            *dest++ = *src++;
  79.        }
  80.        src++;
  81.        dest = Net.UserID;
  82.        while (*src != '\0') {
  83.            *dest++ = *src++;
  84.        }
  85.        indx++;
  86.        strcpy (Password, Arguments [indx]);
  87.     } else {
  88.        *Server = '\0';
  89.        *Net.UserID = '\0';
  90.        Timeout = atoi (Arguments [indx]);
  91.     }
  92. }
  93.  
  94. int help (void)
  95. {
  96.     parse ();
  97.     clrscr ();
  98.     cprintf ("\n\r@NET - LANtastic Network Functions with Indirect File Support");
  99.     cprintf ("\n\r\n\rSupported commands are:");
  100.     cprintf ("\n\r        HELP        - Display this screen");
  101.     cprintf ("\n\r        LOGIN       - Login to a server");
  102.     cprintf ("\n\r        LOGOUT      - Log out of a server");
  103.     cprintf ("\n\r        USE         - Use a resource of a server");
  104.     cprintf ("\n\r        UNUSE       - Release a resource of a server");
  105.     cprintf ("\n\r        LPT TIMEOUT - Set printer timeouts");
  106.     cprintf ("\n\r");
  107.     cprintf ("\n\r        @<FNAME>    - Execute commands from file <FNAME>");
  108.     cprintf ("\n\r\n\rPress a key to continue");
  109.     getch ();
  110.  
  111.     return 0;
  112. }
  113.  
  114. int login (void)
  115. {
  116.     int retc = FALSE;
  117.  
  118.     retc = ServerLogin (Server, Net.UserID, Password);
  119.     return (retc);
  120. }
  121.  
  122. int logout (void)
  123. {
  124.     return (ServerLogout (Server));
  125. }
  126.  
  127. int lpt (void)
  128. {
  129.     return (SetPtrTimeout ((int) Timeout * 18.2));
  130. }
  131.  
  132. int unuse (void)
  133. {
  134.     return (RedirectCancel (Device));
  135. }
  136.  
  137. int use (void)
  138. {
  139.     int     DevType;
  140.     char    RemoteName [40];
  141.  
  142.     sprintf (RemoteName, "\\\\%s\\%s", Server, Net.Resource);
  143.     if (strlen (Device) > 2) {
  144.        DevType = DevTypePtr;
  145.     } else {
  146.        DevType = DevTypeDsk;
  147.     }
  148.     return (RedirectDevice (DevType, Device, RemoteName));
  149. }
  150.  
  151. void ProcessArgs (void)
  152. {
  153.     int j;
  154.  
  155.     j = 0;
  156.     indx = 1;
  157.     strupr (Arguments [indx]);
  158.     while ((strcmp (Arguments [indx], ValidCommands[j].Command) != 0) & (j < MAX_CMDS)) {
  159.         j++;
  160.     }
  161.     if (j < MAX_CMDS) {
  162.         indx++;
  163.         parse ();
  164.         (ValidCommands[j].Function) ();
  165.     } else {
  166.         cprintf ("\n\rInvalid command: <%s>", Arguments [indx]);
  167.     }
  168. }
  169.  
  170. main (int argc, char **argv)
  171. {
  172.     int     j;
  173.     char    *ptr;
  174.  
  175.     clrscr ();
  176.     if (argc < 2) {
  177.        help ();
  178.        exit (1);
  179.     }
  180.     Arguments = argv;
  181.     if (argv [1][0] == '@') {
  182.        if ((CmdStream = fopen(&argv [1][1], "rt")) == NULL) {
  183.           cprintf ("\n\n\rUnable to open indirect file %s\n\r", argv [1]);
  184.        } else {
  185.           FileArgs = calloc (MAX_ARGS, MAX_ARG_SIZE);
  186.           Arguments = FileArgs;
  187.           while (NULL != fgets (Buffer, sizeof (Buffer) - 1, CmdStream)) {
  188.               FileArgs [0] = "@NET.C";
  189.               j = 1;
  190.               ptr = strtok (Buffer, " ");
  191.               while (ptr != NULL) {
  192.                   if ((j == 1) & (stricmp (ptr, "NET") == 0)) {
  193.                       ptr = strtok (NULL, " ");
  194.                   } else {
  195.                       FileArgs [j] = calloc (1, strlen (ptr) + 1);
  196.                       strcpy (FileArgs [j], ptr);
  197.                       ptr = strtok (NULL, " ");
  198.                       j++;
  199.                   }
  200.               }
  201.               j--;
  202.               ptr = strchr (FileArgs [j], '\n');
  203.               if (ptr != NULL) {
  204.                  *ptr = '\0';
  205.               }
  206.               ProcessArgs ();
  207.           }
  208.        }
  209.     } else {
  210.        ProcessArgs ();
  211.     }
  212. }
  213.  
  214.